// pages/cashWithdrawal-list/cashWithdrawal-list.js
import {
	recharge,userBalance
} from '../../utils/request/apiurl'
import api from '../../utils/request/api'
const util = require('../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
	uid:'',
	dataList:[],//列表
	searchGood: {
		page: 1,
		size: 10,
		pages: 0
	},
	isRequest: false,
	type:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  // console.log(options)
	  if(options.type==1){
		  // 充值
		  this.setData({
			  type:1
		  })
		  this.getrechargeList()
	  }else{
		 this.getApplyList() 
	  }
	
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
	this.setData({
		uid:wx.getStorageSync('userInfo').uid
	})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
	// wx.showNavigationBarLoading() //在标题栏中显示加载
	// 
	// this.onLoad()
	// setTimeout(function() {
	// 	wx.hideNavigationBarLoading() //完成停止加载
	// 	wx.stopPullDownRefresh() //停止下拉刷新
	// }, 1500);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
	if (!this.data.isRequest && this.data.searchGood.page < this.data.searchGood.pages) {
		this.setData({
		  searchGood: {
		    page: this.data.searchGood.page + 1,
		    size: 10,
		    pages: this.data.searchGood.pages
		  }
		})
		this.getApplyList() 
	}
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //提现记录列表
  getApplyList(){
	  var source={
	  	uid:this.data.uid||wx.getStorageSync('userInfo').uid,
		page: this.data.searchGood.page,
		size: this.data.searchGood.size,
	  }
	  // console.log(source)
	  api.post(userBalance.getApplyList, source).then(res => {
	  	// console.log(res)
	  	let list = res.rows
	  	list.map(a => {
	  	  a.applyTime = util.getLocalTime(a.applyTime)
	  	  return a
	  	})
	  	this.setData({
	  	  dataList: list
	  	})
	  	// this.setData({
	  	// 	dataList:res
	  	// })
	  }).catch(err => {
	  	// console.log(err)
	  	wx.showToast({
	  		title: err.message,
	  		icon: 'none'
	  	})
	  })
  },
  // 充值记录列表
  getrechargeList(){
	var source={
		uid:this.data.uid||wx.getStorageSync('userInfo').uid
	}
	// console.log(source)
	api.post(recharge.getrechargeList, source).then(res => {
		// console.log(res)
		let list = res
		list.map(a => {
		  a.recordTime = util.getLocalTime(a.recordTime)
		  return a
		})
		this.setData({
		  dataList: list
		})
		// this.setData({
		// 	dataList:res
		// })
	}).catch(err => {
		// console.log(err)
		wx.showToast({
			title: err.message,
			icon: 'none',
			duration:2000
		})
	})
	
	  
  },
})